// 餐厅详情页面逻辑
const app = getApp();
const baseUrl = 'http://120.76.157.24/api/v1';

Page({
    // 页面的初始数据
    data: {
        restaurant: null,
        loading: true
    },

    // 生命周期函数--监听页面加载
    onLoad: function (options) {
        const id = options.id;
        if (id) {
            this.loadRestaurantDetail(id);
        } else {
            wx.showToast({
                title: '参数错误',
                icon: 'none'
            });
            setTimeout(() => {
                wx.navigateBack();
            }, 1500);
        }
    },

    // 加载餐厅详情
    loadRestaurantDetail: function (id) {
        this.setData({ loading: true });

        // 模拟请求餐厅详情
        // 实际项目中应该调用真实接口
        // wx.request({
        //   url: `${baseUrl}/restaurants/${id}`,
        //   success: (res) => {...}
        // });

        // 模拟数据
        setTimeout(() => {
            const mockDetail = {
                id: id,
                name: '海底捞火锅',
                location: '广州市天河区天河路123号',
                officialScore: 4.8,
                officialComment: '服务周到，食材新鲜',
                averagePrice: 120,
                userReviewCount: 1542,
                userAverageScore: 4.7,
                imageUrl: 'https://img.example.com/restaurant1.jpg',
                openingHours: '10:00-22:00',
                telephone: '020-12345678',
                category: '火锅',
                reviews: [
                    {
                        id: 101,
                        username: '美食家',
                        content: '非常好吃，服务也很周到',
                        score: 5,
                        date: '2023-05-01'
                    },
                    {
                        id: 102,
                        username: '小吃货',
                        content: '食材新鲜，环境舒适',
                        score: 4.5,
                        date: '2023-04-15'
                    }
                ]
            };

            this.setData({
                restaurant: mockDetail,
                loading: false
            });
        }, 500);
    },

    // 返回上一页
    navigateBack: function () {
        wx.navigateBack();
    },

    // 调用电话
    callPhone: function () {
        if (this.data.restaurant && this.data.restaurant.telephone) {
            wx.makePhoneCall({
                phoneNumber: this.data.restaurant.telephone
            });
        }
    },

    // 查看位置
    viewLocation: function () {
        wx.showToast({
            title: '地图功能开发中',
            icon: 'none'
        });
    }
}); 